<template>
  <div>
    <list-page :data="listPageConfig">
      <template v-slot:tableColumn>
        <el-table-column
          align="center"
          label="小结日期"
          prop="date"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="组织架构"
          prop="org_title"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="添加时间"
          prop="addTime"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="通知人数"
          prop="noticeNum"
          show-overflow-tooltip
        />
        <el-table-column align="center" label="操作">
          <template v-slot="{ row }">
            <el-button type="text" size="small" @click="toDetail(row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </template>
    </list-page>
    <add-dialog
      v-model="addDialog"
      :data="createData"
      @success="success"
    ></add-dialog>
  </div>
</template>

<script>
import tableMixin from '@/mixin/tablePageMixin'
import ListPage from '@/views/_common/ListPage'
import AddDialog from './components/addDialog.vue'
import { request } from '@/api/request'

export default {
  name: 'WorkSumManage',

  components: {
    ListPage,
    AddDialog
  },

  mixins: [tableMixin],

  data() {
    return {
      addDialog: false,
      createData: {
        org: {
          version: null,
          title: null
        },
        q1: null,
        q2: null,
        q3: null,
        q4: null,
        q5: null,
        t: null,
        allQ: null
      }
    }
  },

  computed: {
    listPageConfig() {
      return {
        pageLoading: this.config.operating,
        dataLoading: this.config.loading,
        buttons: [
          {
            type: 'primary',
            content: '创建工作小结通知',
            e: this.createWorkSumNotice
          }
        ],
        table: {
          props: { data: this.tableData },
          on: { 'row-click': this.rowClick }
        },
        pagination: {
          props: { model: this.searchForm },
          on: {
            'current-change': this.pageChange,
            'size-change': this.pageSizeChange
          }
        }
      }
    }
  },

  methods: {
    success() {
      this.search()
    },

    toDetail(row) {
      this.$router.push(
        `/groupManage/workSum/workSumManage/detail/${row.id}/${row.date}`
      )
    },

    // 创建工作小结通知
    createWorkSumNotice() {
      request(
        'company/workSum/workSumNotice/createWorkSumNotice',
        {},
        (res) => {
          this.createData = res.data
          this.addDialog = true
        }
      )
    },

    search() {
      if (this.config.loading) return
      this.config.loading = true
      request(
        'company/workSum/workSumNotice/index',
        { p: this.searchForm.page, limit: this.searchForm.pageSize },
        (res) => {
          this.searchForm.total = res.data.count
          this.tableData = res.data._list
        }
      ).finally(() => {
        this.config.loading = false
      })
    }
  }
}
</script>
